// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  // 修改资源地址
  srcDir: "src/",

  devtools: { enabled: true },
  modules: ["@element-plus/nuxt", "@unocss/nuxt", "@pinia/nuxt", "@pinia-plugin-persistedstate/nuxt", "@vueuse/nuxt"],

  vite: {
    esbuild: {
      drop: process.env.NODE_ENV === "production" ? ["console", "debugger"] : []
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "~/styles/element-custom.css" as element;`
        }
      }
    }
  },

  elementPlus: {
    importStyle: "scss"
  },

  css: ["~/styles/main.css"],

  postcss: {
    plugins: {
      tailwindcss: {},
      autoprefixer: {}
    }
  },

  devServer: {
    port: 8080,
    open: true,
    proxy: {
      "/web-api": {
        target: import.meta.env.NUXT_API_BASE,
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp('^web-api'), '')
      },
    },
  },

  runtimeConfig: {
    // public 中的密钥也暴露在客户端
    public: {
      // apiBase命名，不能随意更改，否则不生效
      apiBase: import.meta.env.NUXT_API_BASE || "api"
    }
  },

  compatibilityDate: "2024-11-30"
})